Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix for split_non_commuting when tape measurements is empty #5869

Merged
merged 4 commits into from
Jun 17, 2024

Conversation

lillian542
Copy link
Contributor

@lillian542 lillian542 commented Jun 17, 2024

Context:
Currently on master, if we apply split_non_commuting to a tape with empty measurements, we delete the tape:

>>> from pennylane.transforms import split_non_commuting
>>> tape = qml.tape.QuantumScript([qml.X(0)], measurements=[])
>>> tapes, _ = split_non_commuting(tape)
>>> tapes
[]

Description of the Change:

We add a check for len(measurements) == 0 and just return the tape if there are no measurements to split, so we get:

>>> from pennylane.transforms import split_non_commuting
>>> tape = qml.tape.QuantumScript([qml.X(0)], measurements=[])
>>> tapes, _ = split_non_commuting(tape)
>>> tapes
[<QuantumScript: wires=[0], params=0>]

Benefits:
We don't delete the tape if it has no measurements (came up in catalyst tests)

@lillian542 lillian542 marked this pull request as ready for review June 17, 2024 20:16
Copy link
Contributor

Hello. You may have forgotten to update the changelog!
Please edit doc/releases/changelog-dev.md with:

  • A one-to-two sentence description of the change. You may include a small working example for new features.
  • A link back to this PR.
  • Your name (or GitHub username) in the contributors section.

Copy link
Contributor

@mudit2812 mudit2812 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one comment, otherwise LGTM! Here's a 🚀

pennylane/transforms/split_non_commuting.py Outdated Show resolved Hide resolved
Copy link

codecov bot commented Jun 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.67%. Comparing base (fb06ce8) to head (2b569d0).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5869      +/-   ##
==========================================
- Coverage   99.68%   99.67%   -0.01%     
==========================================
  Files         421      421              
  Lines       40457    40165     -292     
==========================================
- Hits        40328    40035     -293     
- Misses        129      130       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@astralcai astralcai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lillian542
Copy link
Contributor Author

[sc-60186]

@lillian542 lillian542 enabled auto-merge (squash) June 17, 2024 21:46
@lillian542 lillian542 merged commit d90137d into master Jun 17, 2024
40 checks passed
@lillian542 lillian542 deleted the bugfix_split_non_commuting branch June 17, 2024 22:12
@lillian542
Copy link
Contributor Author

lillian542 commented Jun 20, 2024

Edit: wrong story ID
[sc-60187]

@lillian542
Copy link
Contributor Author

[sc-60188]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants